// pages/infoList/infoList.js
var app = getApp()
Page({
  data: {
    page: 1,
  },
  zxlist: function (page, that) {
    var url = app.data.url
    //资讯列表
    wx.request({
      url: '' + url + '/Shop/Article/List',
      data: { page: page },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        wx.setStorageSync('PageCount', res.data.PageCount);
        wx.setStorageSync('page', page)
        if (res.data.Rows.length > 0) {
          if (that.data.infolist) {
            var infolist = that.data.infolist
            var shuju = res.data.Rows
            infolist.concat(shuju)
            that.setData({
              infolist: infolist,
              page: page,
            })
          } else {
            var shuju = res.data.Rows
            that.setData({
              infolist: shuju,
              page: page,
            })
          }
        } else {
          that.setData({
            infolist: infolist,
            page:page
          })
        }
        console.log(that.data.infolist)
      },
      error: function (res) {
        console.log(res)
      }
    })
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var url = app.data.url
    //资讯列表
    var that = this;
    that.zxlist(1, that)
    //获取设备信息
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          height: res.windowHeight,
          width: res.windowWidth
        })
      }
    })
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
    wx.clearStorageSync('page')
    wx.clearStorageSync('PageCount')
  },
  onUnload: function () {
    // 页面关闭
    wx.clearStorageSync('page')
    wx.clearStorageSync('PageCount')
  },
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var page = that.data.page;
    page++;
    if (wx.getStorageSync('PageCount') >= page) {
      if (wx.getStorageSync('page') == page) {
        return
      }
      else {
        that.zxlist(page, that)
      }
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  //   return {
  //     title: ' ',
  //     success: function (res) {
  //       // 转发成功
  //     },
  //     fail: function (res) {
  //       // 转发失败
  //     }
  //   }
  // }
})